/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import bo.UserBO;
import java.awt.Checkbox;
import java.io.IOException;
import java.io.PrintWriter;
import javabean.UserBean;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Admin
 */

public class DeleteUserServlet extends HttpServlet {

   
    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        UserBO userBO = new UserBO();
        try {
            UserBean user = userBO.isExist(username, password);
            HttpSession session = request.getSession();
            Object attribute = session.getAttribute("username"); //dua ten username vao session
            if (user != null && user.getRole().equals("admin")) {
                response.sendRedirect("jsp/Account/AdminFunctions.jsp");
            }
            else {
                if (user != null && user.getRole().equals("user")) {
                    response.sendRedirect("./jsp/Account/UserFunctions.jsp");
                }
                else {
                    response.sendRedirect("./jsp/Account/LoginFailed.jsp");
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    
    }
}
